﻿
namespace FastFood.DataAccess
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using EDOSwit.Entity;
    using FastFood.Business.Entities;
    using FastFood.Business.Entities.Tipos;

    public class DetalleVendiblesData : Singleton<DetalleVendiblesData>
    {
        #region Attributes

        private readonly Database BaseDatos = DatabaseFactory.CreateDatabase();

        #endregion

        #region Methods

        public IList<DetalleVendibles> ListarByVentaID(int ventaID)
        {
            var entidades = new List<DetalleVendibles>();
            var comando = BaseDatos.GetStoredProcCommand("SelectDetallesVendiblesByVentaID");

            BaseDatos.AddInParameter(comando, "ventaID", DbType.String, ventaID);

            using (var lector = BaseDatos.ExecuteReader(comando))
            {
                while (lector.Read())
                {
                    entidades.Add(new DetalleVendibles
                    {
                        vendibleID = lector.IsDBNull(lector.GetOrdinal("vendibleID")) ? default(short) : lector.GetInt16(lector.GetOrdinal("vendibleID")),
                        nombre = lector.IsDBNull(lector.GetOrdinal("nombre")) ? default(string) : lector.GetString(lector.GetOrdinal("nombre")),
                        precioBruto = lector.IsDBNull(lector.GetOrdinal("precio")) ? default(decimal) : lector.GetDecimal(lector.GetOrdinal("precio")),
                        cantidad = lector.IsDBNull(lector.GetOrdinal("cantidad")) ? default(byte) : lector.GetByte(lector.GetOrdinal("cantidad")),
                        tipo = (TipoVendible)(lector.GetInt32(lector.GetOrdinal("tipo")))
                    });
                }
            }
            comando.Dispose();
            return entidades;
        }

        #endregion
    }
}
